// const BASE_URL = 'http://api-breakingnews-web.itheima.net'

// 是否登录
let token = localStorage.getItem('token')
if (!token) {
  location.href = './login.html'
}

// 获取个人信息
function getUserInfo() {
  myUserInfo(res => {
    let { status, message } = res.data
    if (status === 1 && message === '身份认证失败！') {
      localStorage.removeItem('token')
      location.href = '/login.html'
      return
    }
    let { username, nickname, user_pic } = res.data.data
    if (nickname === '') {
      nickname = username
    }
    $('.nickname').html(nickname)

    if (user_pic === null) {
      let first = nickname[0].toUppercase()
      $('.avatar').html(first)
      $('.avatar').css('display', 'inline-block')
    } else {
      $('.layui-nav-img').attr('src', user_pic)
      $('.layui-nav-img').css('display', 'inline-block')
    }
  })
}
getUserInfo()

// 退出
$('#logout').on('click', function () {
  layer.confirm('确定退出吗?', { icon: 3, title: '退出登录' }, function (index) {
    localStorage.removeItem('token')
    location.href = './login.html'

    layer.close(index)
  })
})
